// Created by wangliang on 2025/6/27.
import 'package:flutter/material.dart';
import 'package:flutter_app_demo/base/widget/common_app_bar.dart';
import 'package:flutter_app_demo/pages/live/live_camera_push_page_view_model.dart';
import 'package:go_router/go_router.dart';
import 'package:live_flutter_plugin/widget/v2_tx_live_video_widget.dart';
import 'package:mvvm_plus/mvvm_plus.dart';

class LiveCameraPushPage extends ViewWidget<LiveCameraPushPageViewModel> {
  LiveCameraPushPage({super.key}) : super(builder: () => LiveCameraPushPageViewModel());

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: CommonAppBar(
        onBackPressed: () => context.pop(),
        title: 'Camera Push',
      ),
      body: Stack(
        children: [renderView()],
      ),
    );
  }

  bool _isStartPush = false;
  Widget renderView() {
    return V2TXLiveVideoWidget(
      onViewCreated: (viewId) async {
        viewModel.localViewId = viewId;
        if (_isStartPush == false) {
          _isStartPush = true;
          Future.delayed(const Duration(seconds: 1), () {
            viewModel.startPush();
          });
        }
      },
    );
  }
}
